package decorator

import (
	"github.com/sirupsen/logrus"
	"golang.org/x/net/context"
)

// 这里的返回值R，目的是为了让系统更方便感知到操作的结果（如订单操作--返回订单号）
type CommandHandler[C, R any] interface {
	Handle(c context.Context, query C) (R, error)
}

func ApplyCommandDecorators[H, R any](handler CommandHandler[H, R], logger *logrus.Entry, metricsClient MetricsClient) CommandHandler[H, R] {
	return queryLoggingDecorator[H, R]{ //类型等价
		logger: logger,
		base: queryMetricsDecorator[H, R]{
			client: metricsClient,
			base:   handler,
		},
	}
}
